var main = {
	init: function(){
		var boss = this;
		boss.initLayout();
		boss.initEvent();
		var actionName = sbl.getParameter("action");
		if(actionName != null && actionName !=""){
			var actionT = window.location.search.substr(1);
			actionName =actionT.substr(7,actionT.length);
			boss.gotoAction(actionName);
		}
	},
	initLayout: function(){
		var boss = this;
		boss.reSize();
		$(".first_menu, .third_menu").attr("checked", "checked");
		$(".third_menu").hide();
		if(boss.getQueryString("action") != null && boss.getQueryString("action") != ""){
			var tag = boss.getQueryString("action");
			boss.selectMenu(tag);
		}
	},
	selectMenu:function(actionName){
		var tag =actionName;
		var menu = $("#nav_menu").find("a[tag='"+tag+"']");
		
		if(menu.parents(".third_menu")){
			menu.parents(".third_menu").prev().attr("checked", "checked");
			menu.parents(".third_menu").show();
		}
		menu.css("font-size", "16px");
		menu.css("color", "red");
		menu.css("font-weight", "bold");
	},
	initEvent: function(){
		var boss = this;
		$(".first_menu").bind("click", function(){
			var checked = $(this).attr("checked");
			if(checked){
				$(this).next().hide();
				$(this).removeAttr("checked");
			}else{
				$(this).next().show();
				$(this).attr("checked", "checked");
			}
		});
		$(".menu_info").bind("click", function(){
			
		});
		$(".menu_title").bind("click", function(){
			var checked = $(this).attr("checked");
			if(checked){
				$(this).next().hide();
				$(this).removeAttr("checked");
			}else{
				$(this).next().show();
				$(this).attr("checked", "checked");
			}
		});
		$(".span_gl").bind("click",function(){
			var tag = $(this).attr("tag");
			window.location.href = burl + "/view/manager/main.jsp?action=" + tag;
		});
	},
	gotoAction:function(actionName){
		var boss = this;
		sbl.ajax({
			url: burl + actionName,
			dataType: "html",
			success: function(d){
				$("#content").html(d);
				var tag = $("#parentMenu").val();
				if(tag != null && tag != ""){
					boss.selectMenu(tag);
				}
			}
		});
	},
	reSize: function(){
		var bodyWidth = document.documentElement.clientWidth;
		var bodyHeight = document.documentElement.clientHeight;
		var mainWidth = bodyWidth;
		var mainHeight = bodyHeight - $(".top").outerHeight() - $(".low").outerHeight() - 6;
		var menuWidth = $(".menu_main").outerWidth();
		var menuHeight = bodyHeight - $(".top").outerHeight() - $(".low").outerHeight() - 69;
		var gridWidth = bodyWidth - $(".menu_main").outerWidth() - 18;
		var gridHeight = mainHeight;
		$(".main").css("width", mainWidth);
		$(".main").css("height", mainHeight);
		$(".menu").css("width", menuWidth);
		$(".menu").css("height", menuHeight);
		$(".content").css("width", gridWidth-16);
		$(".content").css("height", gridHeight-16);
	},
	getQueryString : function(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if (r != null) return unescape(r[2]);
		return null;
    }
};
$(function(){
	main.init();
});